package com.heyun.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.heyun.bean.HeyunCustomer;
import com.heyun.bean.HeyunMerchandise;
import com.heyun.bean.HeyunOrder;
import com.heyun.bean.HeyunOrderMerchandise;
import com.heyun.bean.HeyunShoppingCart;
import com.heyun.dao.HeyunEmpOrderDao;
import com.heyun.dao.HeyunMerchandiseDao;
import com.heyun.dao.HeyunCustomerOrderDao;
import com.heyun.dao.HeyunOrderDao;
import com.heyun.dao.HeyunOrderMerchandiseDao;
import com.heyun.dao.HeyunShoppingCartDao;
import com.heyun.service.HeyunOrderService;
/**
 * @author zll
 * @Description 查询所有员工Impl
 * @Company 
 * @date 2017年12月14日
 */
@Service
public class HeyunOrderServiceImpl implements HeyunOrderService {
	@Autowired
	private HeyunMerchandiseDao listMerchandise;
	@Autowired
	private HeyunCustomerOrderDao HeyunCustomerOrder;
	@Autowired
	private HeyunOrderDao orderOrderDao;
	@Autowired
	private HeyunOrderMerchandiseDao heyunOrderMerchandiseDao;
	@Autowired
	private HeyunShoppingCartDao heyunShoppingCartDao;
	@Autowired
	private HeyunEmpOrderDao heyunEmpOrderDao;
	/**
	 *订单查看根据订单id查询商品
	 */
	@Override
	public List<HeyunOrderMerchandise> getOrderMerchandiseOrCusId(int orCusId){
		return heyunOrderMerchandiseDao.getOrderMerchandiseOrCusIdDao(orCusId);
	}
	/**
	 *订单查看部分的查询订单ID
	 */
	@Override
	public List<HeyunOrder> listOrCusId(int cusId) {
		// TODO Auto-generated method stub
		return orderOrderDao.listOrCusIdDao(cusId);
	}
	
	/**
	 *订单查看
	 */
	@Override
	public HeyunOrder getOrderManagement(int cusId){
		return orderOrderDao.getOrderManagementDao(cusId);
	}
	/**
	 * 待下订单部分的首页默认显示的统计总金额
	 */
	@Override
	public List<HeyunOrder> getOrderMoney(int cusId){
		return orderOrderDao.getOrderMoneyDao(cusId);
	}
	/**
	 * 待下订单部分的首页默认显示的客户基本信息
	 */
	@Override
	public List<HeyunOrder> getOrderUser(HeyunOrder heyunOrder){
		return orderOrderDao.getOrderUserDao(heyunOrder);
	}
	/**
	 * 查询员工部门
	 */
	@Override
	public String getDaptOrder(int empId){
		return heyunEmpOrderDao.getDaptOrderDao(empId);
	}
	/**
	 * 添加成功后删除购物车中的信息
	 */
	@Override
	public int delHeyunShoppingCart(){
		return heyunShoppingCartDao.delHeyunShoppingCartDao();
	}
	/**
	 * 添加订单中的商品
	 */
	@Override
	public int addHeyunOrderMerchandiseService(HeyunOrderMerchandise heyunOrderMerchandise){	
		return heyunOrderMerchandiseDao.addHeyunOrderMerchandise(heyunOrderMerchandise);
	}
	/**
	 * 添加商品
	 */
	@Override
	public int addOrder(HeyunOrder heyunOrder){
		return orderOrderDao.addOrderDao(heyunOrder);
	}
	/**
	 * 查询购物车的信息
	 */
	@Override
	public List<HeyunShoppingCart> getShoppingCart(){
		return heyunShoppingCartDao.getListShoppingCart();
	}
	/**
	 * 向购物表中添加信息
	 */
	@Override
	public int addShoppingCart(HeyunShoppingCart shopping){
		return heyunShoppingCartDao.addShoppingCart(shopping);
	}
	/**
	 * 根据用户名查询用户总消费金额和总消费次数
	 */
	@Override
	public Map<String,Object> listTotalConsumption(String userName) {
		// TODO Auto-generated method stub
		List<HeyunOrder> listHeyunOrder = orderOrderDao.listTotalConsumption(userName);
		int totalQuantity = 0;
		double totalAmount = 0.00;
		for(int i=0;listHeyunOrder.size()>i;i++){
			totalQuantity += 1;
			int orCusId = listHeyunOrder.get(i).getOrCusId();
			List<HeyunOrderMerchandise> listOrderMerchandise=heyunOrderMerchandiseDao.getTotalPrice(orCusId);
			for(int j=0;listOrderMerchandise.size()>j;j++){
				double price = listOrderMerchandise.get(j).getOrMerPrice();
				int number = listOrderMerchandise.get(j).getOrNumber();
				totalAmount += (price*number);
			}
		}
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("totalQuantity", totalQuantity);
		map.put("totalAmount", totalAmount);
		return map;
	}
	/**
	 * 根据ID查询客户信息
	 */
	@Override
	public HeyunCustomer getHeyunCustomer(String userName) {
		// TODO Auto-generated method stub
		return HeyunCustomerOrder.GetHeyunCustomer(userName);
	} 
	/**
	 * 查询所有商品
	 */
	@Override
	public List<HeyunMerchandise> listMerchandise() {
		// TODO Auto-generated method stub
		return listMerchandise.listMerchandise();
	}
	@Override
	public List<HeyunCustomer> selectList() {
		// TODO Auto-generated method stub
		return null;
	}
}
